package com.cxrj.zhsq.userManage.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;

import com.cxrj.zhsq.userManage.dao.LogMapper;
import com.cxrj.zhsq.userManage.service.LogService;

@Service
public class LogServiceImpl implements LogService {

	@Resource
	private LogMapper logMapper;

	@Override
	public Map<String, Object> selectLogsPager(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> sqlMap = new HashMap<String, Object>();
		// String str = " 1=1 and l.project_id='1'";
		// if
		// (request.getSession().getAttribute("roleId").equals("0084ae3f-3764-48d1-989c-0e9241e178a9"))
		// {
		String str = " 1=1 and l.project_id='1'";
		// }
		response.setContentType("text/html;charset=utf-8");
		// 数据起始位置
		String start = request.getParameter("offset");
		// 数据长度
		String length = request.getParameter("limit");
		//查询条件
		String kod=request.getParameter("kod");
		if(kod!=null&&!kod.equals("")){
			String[] a=kod.split("~");
			String startTime=a[0];
			String endTime=a[1];
			sqlMap.put("startTime", startTime+"00:00:00");
			sqlMap.put("endTime", endTime+" 23:00:00");
		}
		// 总记录数
		String recordsTotal = "0";
		
		sqlMap.put("start", Integer.parseInt(start));
		sqlMap.put("condition", " where " + str);
		sqlMap.put("length", Integer.parseInt(length));
		// 获取数据库总记录数
		recordsTotal = logMapper.getLogCount(sqlMap) + "";
		List<Map<String, Object>> list = logMapper.selectLogsPager(sqlMap);

		resultMap.put("total", recordsTotal);
		resultMap.put("recordsFiltered", recordsTotal);
		resultMap.put("rows", list);

		return resultMap;
	}

}
